package com.zygh.policeasset.controller;

import com.zygh.policeasset.component.CommonResult;
import com.zygh.policeasset.pojo.DailyProject;
import com.zygh.policeasset.service.DailyAssetsService;
import com.zygh.policeasset.service.DailyProjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping({"/dailyProject"})
@Api(tags = {"日常资产项目管理"})
@RestController
/* loaded from: police-asset-2.0-0.0.1-SNAPSHOT.jar:BOOT-INF/classes/com/zygh/policeasset/controller/DailyProjectController.class */
public class DailyProjectController {
    @Autowired
    DailyProjectService dailyProjectService;
    @Autowired
    DailyAssetsService dailyAssetsService;

    @RequestMapping(value = {"/findbyid"}, method = {RequestMethod.GET})
    @ApiOperation("根据ID查询")
    public Object selectOne(Integer id) {
        DailyProject dailyAsset = this.dailyProjectService.findById(id);
        if (StringUtils.isEmpty(dailyAsset)) {
            return new CommonResult().validateFailed("查询失败");
        }
        return new CommonResult().success(dailyAsset);
    }

    @RequestMapping(value = {"/add"}, method = {RequestMethod.POST})
    @ApiOperation("添加")
    public Object add(@RequestBody DailyProject dailyAsset) {
        if (this.dailyProjectService.selectByName(dailyAsset.getProjectName()).intValue() > 0) {
            return new CommonResult().validateFailed("工程名称录入重复，请检查工程名称是否已录入！！！");
        }
        if (this.dailyProjectService.add(dailyAsset) > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("添加失败");
    }

    @RequestMapping(value = {"/delete"}, method = {RequestMethod.GET})
    @ApiOperation("删除")
    public Object delete(Integer id) {
        int count = this.dailyProjectService.deleteById(id);
        this.dailyAssetsService.deleteBybuildNum(String.valueOf(id));
        if (count > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("删除失败");
    }

    @RequestMapping(value = {"/update"}, method = {RequestMethod.POST})
    @ApiOperation("修改")
    public Object update(@RequestBody DailyProject dailyAsset) {
        if (this.dailyProjectService.update(dailyAsset) > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("修改失败");
    }

    @RequestMapping(value = {"/findall"}, method = {RequestMethod.GET})
    @ApiOperation("查询全部")
    public Object findall(@RequestParam(defaultValue = "1", value = "pageNum") int pageNum,
                          @RequestParam(defaultValue = "10", value = "pageSize") int pageSize,
                          @RequestParam(value = "assetNewStatus", required = false) Integer assetNewStatus,
                          @RequestParam(value = "company", required = false) String company,
                          @RequestParam(value = "category", required = false) String category,
                          @RequestParam(value = "projectName", required = false) String projectName,
                          @RequestParam(value = "dataLabelsId", required = false) Integer dataLabelsId,
                          @RequestParam(value = "status", required = false) Integer status,
                          @RequestHeader(value = "findAll", required = false) boolean findAll,
                          @RequestHeader(value = "userId", required = false) Integer userId,
                          @RequestParam(value = "combined", required = false) Double combined) {
        if (findAll) {
            return this.dailyProjectService.findAll(pageNum, pageSize, assetNewStatus, company, category, projectName, dataLabelsId, null, status, combined);
        }
        return this.dailyProjectService.findAll(pageNum, pageSize, assetNewStatus, company, category, projectName, dataLabelsId, userId, status, combined);
    }

    @RequestMapping(value = {"/findallExcel"}, method = {RequestMethod.GET})
    @ApiOperation("查询全部导出")
    public Object findallExcel(@RequestParam(value = "assetNewStatus", required = false) Integer assetNewStatus, @RequestParam(value = "constructionuUnit", required = false) String constructionuUnit, @RequestParam(value = "category", required = false) String category, @RequestParam(value = "projectName", required = false) String projectName, @RequestParam(value = "dataLabelsId", required = false) Integer dataLabelsId, HttpServletResponse response, @RequestParam(value = "userId", required = false) Integer userId, @RequestParam(value = "status", required = false) Integer status, @RequestParam(value = "combined", required = false) Double combined) {
        return this.dailyProjectService.findallExcel(assetNewStatus, constructionuUnit, category, projectName, dataLabelsId, response, userId, status, combined);
    }
}